(* Content-type: application/vnd.wolfram.mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* CreatedBy='Mathematica 9.0' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       157,          7]
NotebookDataLength[     12926,        294]
NotebookOptionsPosition[     12610,        279]
NotebookOutlinePosition[     12985,        295]
CellTagsIndexPosition[     12942,        292]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{
Cell["\<\
Lucas Godshalk
Goshen College
This mathematica script takes in photos taken by a Nikon D60 camera (Paul\
\[CloseCurlyQuote]s). The camera\[CloseCurlyQuote]s naming scheme is simply \
\[OpenCurlyDoubleQuote]DSC_XXXXX.JPG\[CloseCurlyDoubleQuote], where X is an \
incremented integer. This script takes advantage of that to import all the \
photos at once by a designated start and end integer, performs an image \
subtraction between each photo of the \[OpenCurlyQuote]moving\
\[CloseCurlyQuote] wave and an unmoving, \[OpenCurlyQuote]neutral\
\[CloseCurlyQuote] reference image, and then stitches the moving photos \
together in an animation. You still need to edit this gif animation in a \
software package like photoshop, the levels of the image need to be adjusted \
almost entirely into the dark region to reveal the wave pattern.
General file naming scheme:
\[OpenCurlyQuote]Animation\[CloseCurlyQuote] + frequency + options \
(damped/undamped,diffuse/specular light source, etc.)
Ex: Animation50Hzdampeddiffuse.jpg\
\>", "Text",
 CellChangeTimes->{{3.5824530660233903`*^9, 3.582453260509197*^9}, {
   3.5824533120970373`*^9, 3.582453359531294*^9}, {3.582453404718775*^9, 
   3.582453408886358*^9}, {3.5825566283080606`*^9, 3.58255663186728*^9}, {
   3.5828871094856853`*^9, 3.582887180438589*^9}, {3.5829030053048697`*^9, 
   3.582903082087223*^9}, 3.582906852235819*^9, {3.5836833399212627`*^9, 
   3.583683360224929*^9}}],

Cell[BoxData[{
 RowBox[{
  RowBox[{"Clear", "[", "img", "]"}], "\[IndentingNewLine]", 
  RowBox[{"(*", 
   RowBox[{
   "Designate", " ", "where", " ", "the", " ", "photos", " ", "are", " ", 
    RowBox[{"stored", "."}]}], "*)"}]}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{
   "SetDirectory", "[", "\"\<C:/Users/lucasmg/Desktop/photos/\>\"", "]"}], 
   ";"}], "\[IndentingNewLine]", 
  RowBox[{"(*", 
   RowBox[{"These", " ", "are", " ", "the", " ", 
    RowBox[{"parameters", ".", " ", "What"}], " ", "is", " ", "the", " ", 
    "beginning", " ", "and", " ", "end", " ", "photo", " ", 
    RowBox[{"number", "?", " ", "What"}], " ", "is", " ", "the", " ", 
    "number", " ", "of", " ", "your", " ", "reference", " ", 
    RowBox[{"photo", "?"}]}], "*)"}]}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"filename", "=", "\"\<Animation70Hzundamped.gif\>\""}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"neutral", "=", "1426"}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"start", "=", "1427"}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"end", "=", "1446"}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"filter", "=", "0"}], ";"}], "\[IndentingNewLine]", 
  RowBox[{"(*", 
   RowBox[{"Initial", " ", "photo", " ", "import"}], 
   "*)"}]}], "\[IndentingNewLine]", 
 RowBox[{"If", "[", 
  RowBox[{
   RowBox[{"neutral", "<", "1000"}], ",", " ", 
   RowBox[{
    RowBox[{
     RowBox[{"img", "[", "neutral", "]"}], "=", 
     RowBox[{"Import", "[", 
      RowBox[{"\"\<DSC_00\>\"", "<>", 
       RowBox[{"ToString", "[", "neutral", "]"}], "<>", "\"\<.JPG\>\""}], 
      "]"}]}], ";"}], ",", "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"img", "[", "neutral", "]"}], "=", 
     RowBox[{"Import", "[", 
      RowBox[{"\"\<DSC_0\>\"", "<>", 
       RowBox[{"ToString", "[", "neutral", "]"}], "<>", "\"\<.JPG\>\""}], 
      "]"}]}], ";"}]}], "]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"n", "=", "start"}], ";", 
   RowBox[{"While", "[", 
    RowBox[{
     RowBox[{"n", "<", 
      RowBox[{"end", "+", "1"}]}], ",", " ", "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{"If", "[", " ", 
       RowBox[{
        RowBox[{"n", "<", "1000"}], ",", 
        RowBox[{
         RowBox[{"string", "=", 
          RowBox[{"\"\<DSC_00\>\"", "<>", 
           RowBox[{"ToString", "[", "n", "]"}], "<>", "\"\<.JPG\>\""}]}], 
         ";"}], ",", 
        RowBox[{
         RowBox[{"string", "=", 
          RowBox[{"\"\<DSC_0\>\"", "<>", 
           RowBox[{"ToString", "[", "n", "]"}], "<>", "\"\<.JPG\>\""}]}], 
         ";"}]}], "]"}], ";", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"img", "[", "n", "]"}], "=", 
       RowBox[{"Import", "[", "string", "]"}]}], ";", "\[IndentingNewLine]", 
      RowBox[{"(*", 
       RowBox[{"Print", "[", "string", "]"}], "*)"}], "\[IndentingNewLine]", 
      RowBox[{"n", "++"}], ";"}]}], "]"}]}], "\[IndentingNewLine]", 
  RowBox[{"(*", 
   RowBox[{
   "Scales", " ", "back", " ", "the", " ", "size", " ", "of", " ", "the", " ",
     "image", " ", 
    RowBox[{
     RowBox[{"(", 
      RowBox[{
      "otherwise", " ", "the", " ", "resulting", " ", "gif", " ", "is", " ", 
       "enormous"}], ")"}], "."}]}], "*)"}]}], "\[IndentingNewLine]", 
 RowBox[{"If", "[", 
  RowBox[{
   RowBox[{"filter", "\[NotEqual]", "0"}], ",", "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{"img", "[", "neutral", "]"}], "=", 
     RowBox[{"MeanFilter", "[", 
      RowBox[{
       RowBox[{"img", "[", "neutral", "]"}], ",", "filter"}], "]"}]}], 
    ";"}]}], "]"}], "\[IndentingNewLine]", 
 RowBox[{"Do", "[", "\[IndentingNewLine]", 
  RowBox[{
   RowBox[{
    RowBox[{
     RowBox[{"img", "[", "n", "]"}], "=", 
     RowBox[{"ImageResize", "[", 
      RowBox[{
       RowBox[{"img", "[", "n", "]"}], ",", "1000"}], "]"}]}], ";", 
    "\[IndentingNewLine]", 
    RowBox[{"If", "[", 
     RowBox[{
      RowBox[{"filter", "\[NotEqual]", "0"}], ",", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{
        RowBox[{"img", "[", "n", "]"}], "=", 
        RowBox[{"MeanFilter", "[", 
         RowBox[{
          RowBox[{"img", "[", "n", "]"}], ",", "filter"}], "]"}]}], ";"}]}], 
     "]"}]}], "\[IndentingNewLine]", ",", " ", 
   RowBox[{"{", 
    RowBox[{"n", ",", " ", "start", ",", " ", "end"}], "}"}]}], 
  "]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"img", "[", "neutral", "]"}], "=", 
    RowBox[{"ImageResize", "[", 
     RowBox[{
      RowBox[{"img", "[", "neutral", "]"}], ",", "1000"}], "]"}]}], ";"}], 
  "\[IndentingNewLine]", 
  RowBox[{"(*", 
   RowBox[{
    RowBox[{"Differences", " ", "the", " ", "two", " ", "images"}], ",", " ", 
    RowBox[{
    "finding", " ", "the", " ", "change", " ", "in", " ", "light", " ", 
     "levels", " ", "between", " ", 
     RowBox[{"the", " ", "'"}], 
     RowBox[{"moving", "'"}], " ", 
     RowBox[{"and", " ", "'"}], 
     RowBox[{"still", "'"}], " ", 
     RowBox[{"frames", ".", " ", "This"}], " ", "reveals", " ", "the", " ", 
     "wave", " ", 
     RowBox[{"pattern", "."}]}]}], " ", "*)"}]}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"Do", "[", "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{
     RowBox[{
      RowBox[{"subtract", "[", "n", "]"}], "=", 
      RowBox[{"ImageDifference", "[", 
       RowBox[{
        RowBox[{"img", "[", "n", "]"}], ",", 
        RowBox[{"img", "[", "neutral", "]"}]}], "]"}]}], ";", 
     "\[IndentingNewLine]", 
     RowBox[{"n", "++"}], ";"}], "\[IndentingNewLine]", ",", " ", 
    RowBox[{"{", 
     RowBox[{"n", ",", " ", "start", ",", " ", "end"}], "}"}]}], "]"}], 
  "\[IndentingNewLine]", 
  RowBox[{"(*", 
   RowBox[{
   "Generates", " ", "a", " ", "table", " ", "and", " ", "then", " ", 
    "creates", " ", "a", " ", "gif", " ", "from", " ", "that", " ", "object", 
    " ", 
    RowBox[{"structure", "."}]}], " ", "*)"}]}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"table", "=", 
   RowBox[{"Table", "[", 
    RowBox[{
     RowBox[{"subtract", "[", "n", "]"}], ",", 
     RowBox[{"{", 
      RowBox[{"n", ",", "start", ",", "end"}], "}"}]}], "]"}]}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"Export", "[", 
   RowBox[{"filename", ",", "table", ",", 
    RowBox[{"\"\<DisplayDurations\>\"", "\[Rule]", "0.25"}]}], "]"}], 
  ";"}]}], "Input",
 CellChangeTimes->{{3.581956375385387*^9, 3.5819564068103867`*^9}, {
   3.581956446857387*^9, 3.581956617018387*^9}, {3.581956655363387*^9, 
   3.581956730483387*^9}, {3.581956835059387*^9, 3.5819568422513866`*^9}, {
   3.5819569828033867`*^9, 3.581957045042387*^9}, {3.581957102676387*^9, 
   3.581957246916387*^9}, {3.5819572773330355`*^9, 3.581957460984298*^9}, {
   3.5820344194814034`*^9, 3.5820344546448865`*^9}, {3.582034502880062*^9, 
   3.582034525949755*^9}, {3.58203457869648*^9, 3.582034587008649*^9}, {
   3.5820347793911495`*^9, 3.5820348486551495`*^9}, {3.582035027680149*^9, 
   3.582035036719149*^9}, {3.5820351545521493`*^9, 3.5820351575751495`*^9}, {
   3.5820352365371494`*^9, 3.582035287529149*^9}, {3.5820361988842435`*^9, 
   3.582036224808651*^9}, {3.582036289042227*^9, 3.582036321127018*^9}, {
   3.5820363658585443`*^9, 3.5820364232028093`*^9}, {3.582036969823149*^9, 
   3.582036990909149*^9}, {3.5822925282038293`*^9, 3.582292560477109*^9}, {
   3.5822926102248898`*^9, 3.582292612302682*^9}, {3.582296178395607*^9, 
   3.582296292100743*^9}, {3.582296434777008*^9, 3.58229647023572*^9}, {
   3.582296502365431*^9, 3.5822965075053453`*^9}, 3.5822968876752253`*^9, {
   3.5822999898307333`*^9, 3.582300011132863*^9}, 3.5823008005658274`*^9, {
   3.582380733252141*^9, 3.582380769405924*^9}, {3.5823815866009235`*^9, 
   3.582381616063924*^9}, {3.5823818530479236`*^9, 3.5823818682069235`*^9}, {
   3.5823819698959236`*^9, 3.5823819719749236`*^9}, {3.5823820088719234`*^9, 
   3.5823820122229233`*^9}, {3.582382057030924*^9, 3.5823820953679237`*^9}, {
   3.58238221974986*^9, 3.582382225805254*^9}, {3.582382676490924*^9, 
   3.5823826820879235`*^9}, {3.5823833951539235`*^9, 
   3.5823834179939237`*^9}, {3.5824504191281967`*^9, 
   3.5824504323563275`*^9}, {3.5824528314576654`*^9, 3.582453061604928*^9}, {
   3.5824532867585716`*^9, 3.582453305455702*^9}, {3.5824533799972467`*^9, 
   3.5824534235918875`*^9}, {3.5824539886612325`*^9, 
   3.5824540056877146`*^9}, {3.5824547668645225`*^9, 
   3.5824547821360493`*^9}, {3.5824552867862377`*^9, 
   3.5824553025676594`*^9}, {3.582455524461919*^9, 3.5824555246099334`*^9}, {
   3.5824555873262043`*^9, 3.5824555903115025`*^9}, {3.582456084974872*^9, 
   3.5824560932403917`*^9}, {3.582466848710956*^9, 3.582466868084956*^9}, {
   3.582468194574361*^9, 3.582468212015361*^9}, {3.5824691388333607`*^9, 
   3.582469149652361*^9}, {3.582556163347267*^9, 3.58255616345686*^9}, {
   3.5825562017686157`*^9, 3.582556288764374*^9}, {3.5825563431995163`*^9, 
   3.582556343436208*^9}, {3.5825563922546616`*^9, 3.5825564059488363`*^9}, {
   3.5825565932495985`*^9, 3.582556615401517*^9}, {3.582885298991373*^9, 
   3.582885315961939*^9}, {3.5828862121899853`*^9, 3.5828862228879156`*^9}, {
   3.5828870791747165`*^9, 3.582887094724161*^9}, {3.582887241413491*^9, 
   3.5828872460680256`*^9}, {3.582887964081763*^9, 3.5828879780953307`*^9}, 
   3.582888022764141*^9, {3.5829029410950303`*^9, 3.582902957872385*^9}, {
   3.5829033155581384`*^9, 3.5829033271896477`*^9}, {3.582903710989006*^9, 
   3.582903724336006*^9}, {3.582904110457455*^9, 3.582904127195129*^9}, {
   3.582904526006592*^9, 3.582904531839842*^9}, {3.582904733578411*^9, 
   3.582904743749411*^9}, {3.582906817308819*^9, 3.582906830992819*^9}, {
   3.5829071685598187`*^9, 3.5829071692518187`*^9}, {3.582907207014819*^9, 
   3.5829072381588187`*^9}, {3.5829079674098186`*^9, 3.582907987240819*^9}, {
   3.5829693497733736`*^9, 3.5829693735138736`*^9}, {3.58296964284783*^9, 
   3.5829696519299216`*^9}, {3.582970806149625*^9, 3.5829708173551054`*^9}, {
   3.5829708854543343`*^9, 3.582970892792268*^9}, {3.5829710704320097`*^9, 
   3.5829710829899845`*^9}, {3.5829711786577024`*^9, 3.58297122440518*^9}, {
   3.58297133041218*^9, 3.5829713809871798`*^9}, 3.5829716965608387`*^9, 
   3.5829718426597133`*^9, {3.582972148161748*^9, 3.5829721854275646`*^9}, {
   3.5829723752389936`*^9, 3.5829723959539933`*^9}, 3.582972520088993*^9, {
   3.5829922271071577`*^9, 3.5829922623518333`*^9}, {3.582992767110888*^9, 
   3.5829927782604265`*^9}, {3.582992866031304*^9, 3.582992866848977*^9}, {
   3.5832456911713715`*^9, 3.5832456997436333`*^9}, {3.5832457450050993`*^9, 
   3.583245756836139*^9}, {3.5832458308781133`*^9, 3.583245876994501*^9}}]
},
WindowSize->{1183, 887},
WindowMargins->{{27, Automatic}, {3, Automatic}},
Magnification:>1.5 Inherited,
FrontEndVersion->"8.0 for Microsoft Windows (64-bit) (February 23, 2011)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[557, 20, 1439, 24, 262, "Text"],
Cell[1999, 46, 10607, 231, 1043, "Input"]
}
]
*)

(* End of internal cache information *)
